package com.ljc.cjgl.entitiy;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class ClassActitvity {
	private Integer id;
	private String name;
	private String manager;
	private String demo;
	private Date date;
	private Integer type; //0:班级活动，1:团支部活动
	@JsonIgnore
	private TbClass tbClass;
	private String creator;
	private String modifier;
	
	@JsonIgnore
	private List<ActivityAttachment> attachments=new ArrayList<>();
	

	public ClassActitvity() {
		super();
	}

	public ClassActitvity(Integer id) {
		super();
		this.id = id;
	}
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(length=50)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(length=20)
	public String getManager() {
		return manager;
	}

	public void setManager(String manager) {
		this.manager = manager;
	}
	
	@Column(length=500)
	public String getDemo() {
		return demo;
	}

	public void setDemo(String demo) {
		this.demo = demo;
	}

	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Temporal(TemporalType.DATE)
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@ManyToOne
	@CreatedBy
	public TbClass getTbClass() {
		return tbClass;
	}

	public void setTbClass(TbClass tbClass) {
		this.tbClass = tbClass;
	}
	
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="activity")
	public List<ActivityAttachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<ActivityAttachment> attachments) {
		this.attachments = attachments;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Transient
	public String getClassName() {
		return tbClass==null?"":tbClass.getName();
	}
	
	
	@Transient
	public Integer getClassId() {
		return tbClass==null?null:tbClass.getId();
	}
}
